Imports System.Data.SqlClient

Friend Class DBIndex
    Inherits DBBase

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub Load(ByRef oObject As SQLAutoDocLib.Index)
        Dim sSQL As String = "select"
        sSQL = sSQL & "     [TableID],"
        sSQL = sSQL & "     [TableRevID],"
        sSQL = sSQL & "     [Name],"
        sSQL = sSQL & "     [Index_Desc],"
        sSQL = sSQL & "     [Keys],"

        sSQL = sSQL & "     [CreateName],"
        sSQL = sSQL & "     [CreateDate],"
        sSQL = sSQL & "     [ChangeName],"
        sSQL = sSQL & "     [ChangeDate]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     tDDIndexes"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        If oData.Rows.Count > 0 Then
            With oObject
                .TableID = oData.Rows(0).Item("TableID")
                .TableRevID = oData.Rows(0).Item("TableRevID")
                .Name = oData.Rows(0).Item("Name")
                .Index_Desc = NullToString(oData.Rows(0).Item("Index_Desc"))
                .Keys = oData.Rows(0).Item("Keys")

                .CreateName = oData.Rows(0).Item("CreateName")
                .CreateDate = oData.Rows(0).Item("CreateDate")
                .ChangeName = NullToString(oData.Rows(0).Item("ChangeName"))
                .ChangeDate = NullToString(oData.Rows(0).Item("ChangeDate"))
            End With
        End If

        oData.Dispose()
    End Sub

    Public Sub Update(ByRef oObject As SQLAutoDocLib.Index)
        Dim sSQL As String = "update tDDIndexes set"
        sSQL = sSQL & "     [TableID]=" & ValueToDBValue(oObject.TableID) & ","
        sSQL = sSQL & "     [TableRevID]=" & ValueToDBValue(oObject.TableRevID) & ","
        sSQL = sSQL & "     [Name]=" & ValueToDBValue(oObject.Name) & ","
        sSQL = sSQL & "     [Index_Desc]=" & ValueToDBValue(oObject.Index_Desc) & ","
        sSQL = sSQL & "     [Keys]=" & ValueToDBValue(oObject.Keys) & ","

        sSQL = sSQL & "     [CreateName]=" & ValueToDBValue(oObject.CreateName) & ","
        sSQL = sSQL & "     [CreateDate]=" & ValueToDBValue(oObject.CreateDate) & ","
        sSQL = sSQL & "     [ChangeName]=" & ValueToDBValue(oObject.ChangeName) & ","
        sSQL = sSQL & "     [ChangeDate]=" & ValueToDBValue(oObject.ChangeDate)
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Add(ByRef oObject As SQLAutoDocLib.Index)
        Dim oNextID As New DBNextIDValue("Index")
        Dim lNextID As Long = oNextID.NextValue
        oObject.ID = lNextID

        Dim sSQL As String = "insert into tDDIndexes ("
        sSQL = sSQL & "     [ID],"
        sSQL = sSQL & "     [TableID],"
        sSQL = sSQL & "     [TableRevID],"
        sSQL = sSQL & "     [Name],"
        sSQL = sSQL & "     [Index_Desc],"
        sSQL = sSQL & "     [Keys],"

        sSQL = sSQL & "     [CreateName],"
        sSQL = sSQL & "     [CreateDate],"
        sSQL = sSQL & "     [ChangeName],"
        sSQL = sSQL & "     [ChangeDate]) values ("

        sSQL = sSQL & ValueToDBValue(oObject.ID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.TableID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.TableRevID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Name) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Index_Desc, 2500) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Keys) & ","

        sSQL = sSQL & ValueToDBValue(oObject.CreateName) & ","
        sSQL = sSQL & ValueToDBValue(oObject.CreateDate) & ","
        sSQL = sSQL & ValueToDBValue(oObject.ChangeName) & ","
        sSQL = sSQL & ValueToDBValue(oObject.ChangeDate) & ")"

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Delete(ByRef oObject As SQLAutoDocLib.Index)
        Dim sSQL As String = "delete from tDDIndexes"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub
End Class
